package com.briup.jz.service.impl;


import com.briup.jz.bean.Comment;
import com.briup.jz.bean.CommentExample;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.dao.CommentMapper;
import com.briup.jz.dao.extend.CommentExtendMapper;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.CustomerException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Resource
    private CommentMapper commentMapper;
    @Resource
    private CommentExtendMapper commentExtendMapper;

    @Override
    public List<Comment> finaAll() {
        return commentMapper.selectByExample(new CommentExample());
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        Comment comment = commentMapper.selectByPrimaryKey(id);
        if(comment ==null){
            throw new CustomerException("删除失败，要删除的数据不存在");
        }

        commentMapper.deleteByPrimaryKey(id);

    }

    @Override
    public void savaOrUpdate(Comment comment) throws CustomerException {
        if(comment.getId() == null){
            commentMapper.insert(comment);
        }else
             commentMapper.updateByPrimaryKey(comment);
    }

    @Override
    public List<CommentExtend> findAllWithChild() {
        return commentExtendMapper.selectAllWithChild();
    }
}


